begintownscript;

variables;
short choice;

body;

beginstate 0; //INIT_STATE
	add_range_to_group(6,10,1); //Loyalists

	//intro dialog
	if(get_flag(3,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"You quietly sneak up to the watchtower, and it's not long until you're within spitting distance of a group of soldiers.",0);
		add_dialog_str(1,"They all carry gear that looks like it was scavenged from somewhere, but their armor is the same. On each soldier's shoulder you can see an emblem of an upside-down crown.",0);
		add_dialog_str(2,"A sinking feeling tells you that these are probably Darkside Loyalists. It looks like Mayor Skellick was right about how serious these rebels are.",0);
		//if party entered town where it can be seen from the fire,
		// then alternate dialogue and Loyalists are alerted
		if(party_can_see_loc(28,17) == 1) {
			add_dialog_str(2,"As you edge closer to get a better look, you step on a dry twig. The sound alerts the soldiers, who immediately notice your presence.",0);
			alert_char(1001);
			}
		//otherwise, general sneaky dialog
		else
			add_dialog_str(2,"Fortunately, you're still far enough away that the soldiers haven't noticed you yet, so you have the element of surprise on your side. Hopefully.",0);
		run_dialog(1);
		set_flag(3,0,1);
		}
	
	//dialog for having emptied out the lantern oil
	if(get_flag(4,2) == 1) {
		reset_dialog();
		add_dialog_str(0,"You hurry back down the stairs as the lantern oil spreads around the watchtower. It's already starting to seep through the cracks in the ceiling.",0);
		add_dialog_str(1,"You really need to leave... now.",0);
		run_dialog(1);
		set_flag(4,2,2);
		}
	
break;

beginstate 1; //EXIT_STATE
	//blowing up the tower
	if(get_flag(4,2) == 2) {
		reset_dialog();
		add_dialog_str(0,"As you leave the oil-drenched watchtower behind, you pick up a handy stick. You quickly turn it into a makeshift torch, light it, and lob it into the top of the watchtower...",0);
		run_dialog(1);
		
		//a poor excuse for a cutscene
		pause(5);
		play_sound(14); //thrown missile
		pause(5);
		play_sound(-11); //fireball
		pause(2);
		play_sound(-51); //shooting flames
		
		reset_dialog();
		add_dialog_str(0,"The watchtower bursts into flame, and quickly starts collapsing. You sit for a while (at a safe distance), and watch the ships off to the south.",0);
		add_dialog_str(1,"It's not long before the ships turn to the north and drop anchor by the island. The distraction worked!",0);
		add_dialog_str(2,"Now you just need to make it back down to your boat and paddle past the Loyalist ships.",0);
		run_dialog(1);
		
		set_town_visibility(3,0); //can't enter the watchtower anymore
		set_flag(4,2,3);
		set_flag(52,1,2);
		}
break;

beginstate 2; //START_STATE
	//Checking for the lead pc each turn... not necessary here
	//pc_counter = 0;
	//while(char_ok(pc_counter) == 0) {
	//	pc_counter = pc_counter + 1;
	//	}
	//lead_char = pc_counter;
	
	//checking to see if the Loyalists are still alive
	if((num_chars_in_group(1) == 0) && (get_flag(3,1) == 0)) {
		reset_dialog();
		add_dialog_str(0,"As the you deal the final blow to the last of the Loyalists, he clutches his chest and utters three words: _Dorikas will prevail._",0);
		if(get_flag(4,1) >= 1)
			add_dialog_str(1,"In spite of the ominous last words, you breathe a sigh of relief. With all of the Loyalists taken care of, maybe you can figure out a way to distract the ships to the south...",0);
		else
			add_dialog_str(1,"When he slumps over, the area falls silent. But then you hear some scuffling from inside the watchtower...",0);
		run_dialog(1);
		set_flag(3,1,1);
		}
break;

beginstate 10; //entering the tower
	if(get_flag(3,2) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"As you step inside the watchtower, it's hard to miss the signs of struggle. The bodies have all been removed, but nobody bothered to clean up the blood.",0);
	run_dialog(1);
	set_flag(3,2,1);
break;

beginstate 15; //stairs up
	//no access if the oil has been spilled
	if(get_flag(4,2) > 0) {
		message_dialog("There is no way you're going back upstairs. You need to get out of the building as quickly as possible, before something manages to light the oil on fire.","");
		block_entry(1);
		end();
		}
	block_entry(1);
	reset_dialog();
	add_dialog_str(0,"There are some stairs here, leading up.",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb the stairs.");
	choice = run_dialog(1);
	if(choice == 2) {
		if(is_combat() == 1) {
			print_str_color("Not while in combat mode.",1);
			end();
			}
		move_to_new_town(4,22,23);
		}
break;